package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.group_details;

import android.util.Log;

import com.wangjiyuan.giftshuo.bean.classifybean.strategy.GroupDetailsBean;

import java.util.List;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by QXL on 2016/11/22.
 */

public class GroupDetPresenter implements GroupDetContract.IContractPresenter {
    private static final String TAG = "================";
    private GroupDetContract.IContractModel iContractModel;
    private GroupDetContract.IContractView iContractView;

    private Subscription subscription;
    public GroupDetPresenter(GroupDetContract.IContractView view){
        this.iContractView=view;
        iContractModel=new GroupDetModel();
    }
    @Override
    public void getGroupDetailObservable(int id, int limit, int offset, String order_by) {
        Observable<GroupDetailsBean> groupDetailObservable =
                iContractModel.getGroupDetailObservable(id, limit, offset, order_by);
        subscription=groupDetailObservable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GroupDetailsBean>() {
                    @Override
                    public void onStart() {
                        super.onStart();
                        Log.e("Test","start");
                    }

                    @Override
                    public void onCompleted() {
                        Log.e("GroupDetr","complete");
                        subscription.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("GroupDetr","error");
//                        StackTraceElement[] stackTrace = e.getStackTrace();
//                        for (StackTraceElement ee: stackTrace) {
//                            Log.e(TAG,ee.toString());
//                        }
                        subscription.unsubscribe();
                    }

                    @Override
                    public void onNext(GroupDetailsBean groupDetailsBean) {
                        Log.e("GroupDetr","next");
                        iContractView.getGroupDetailsData(groupDetailsBean);
                    }
                });
    }
}
